package com.thread;

import java.util.concurrent.atomic.AtomicInteger;

public class ThreadStudy {
	public static void main(String[] args) throws Exception {
//		Thread bt = new B();
//		A a = new A();
//		Thread at = new Thread(a);
//		bt.start();
//		at.start();
		final C c = new C();
		Thread t1 = new Thread(new Runnable() {
			public void run() {
				c.sys1();
			}
		}, "t1");
		Thread t2 = new Thread(new Runnable() {
			public void run() {
				c.sys2();
			}
		}, "t2");
		t1.start();
		t2.start();
	}
}


class A implements Runnable{
	ThreadLocal<Integer> tla = new ThreadLocal<Integer>();
	AtomicInteger ai = new AtomicInteger(10);
	public void run() {
		System.out.println("A implements Runnable");
		tla.set(ai.incrementAndGet());
		System.out.println(tla.get());
	}
	
}

class B extends Thread{
	ThreadLocal<Integer> tlb = new ThreadLocal<Integer>();
	AtomicInteger ai = new AtomicInteger(10);
	@Override
	public void run() {
		System.out.println("B extends Thread");
		tlb.set(ai.incrementAndGet());
		System.out.println(tlb.get());
	}
}

class C {
	public synchronized void sys1(){
		try {
			System.out.println(Thread.currentThread().getName());
			Thread.sleep(4000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	public synchronized void sys2(){
		System.out.println(Thread.currentThread().getName());
	}
}